/*
Web: http://www.jsForms.com
Copyright (C) 2008  Igor Demyanov (mailto:Igor.Demyanov@gmail.com)
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
jsForms.Templates.OpenFileControl='<input type="file"/>';
jsForms.Components.OpenFileControl={
	Init:function()
	{
		this.bind('change',this,this.eventChange);
		return jsForms.Components.Component.Init.call(this);
	},
	eventChange: function(e){
		if (!e.data) {
			return;
		}
		else {
			var files = this.files;
			if (files.length > 0) {
//				for (var i = 0; i < files.length; i++) {
					var file = files[0];
					if (file.fileSize>500*1024)
					{
						alert('File "'+file.fileName+'" is big, max 500Kb!');
						return;
					}
					var text = files[0].getAsBinary();
					var fileName = this.value;
					this.value = '';
					e.data._ExecEvent('onLoad',{filename:fileName, text:text});
	//			}
			}
		}
	}
};

jsForms.CreateCompileInfoByObject(
{
	Name: 'OpenFileControl',
	Properties: {
	},
	Events: {
		onLoad: {}
	}
});
